package com.youbug.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youbug.system.entity.Card;
import com.youbug.system.mapper.CardMapper;
import com.youbug.system.service.ICardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youbug.system.vo.CardVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 官网卡片存储表 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2023-04-15
 */
@Service
public class CardServiceImpl extends ServiceImpl<CardMapper, Card> implements ICardService {

    @Override
    public IPage<Card> getCardPage(CardVo vo) {

        Page<Card> oageParam = new Page<>();

        oageParam.setCurrent(vo.getCurrentPage());

        oageParam.setSize(vo.getPageSize());

        QueryWrapper<Card> wrapper = new QueryWrapper<>();

        if(vo.getValid() != null){

            wrapper.eq("valid", vo.getValid());
        }

        Page<Card> page = this.page(oageParam, wrapper);

        return page;
    }

    @Override
    public List<Card> listBy(CardVo card) {

        QueryWrapper<Card> wrapper = new QueryWrapper<>();

        if(card.getValid() != null){
            wrapper.eq("valid", card.getValid());
        }
        return  this.list(wrapper);
    }
}
